home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 351-375 / disk_351 / pdc / libsrc.lzh / LibSrc / StdIO / fseek.c < prev    next >
C/C++ Source or Header  |  1990-04-07  |  2KB  |  62 lines

  1. /*
  2.  * Libraries and headers for PDC release 3.3 (C) 1989 Lionel Hummel.
  3.  * PDC Software Distribution (C) 1989 Lionel Hummel and Paul Petersen.
  4.  * PDC I/O Library (C) 1987 by J.A. Lydiatt.
  5.  *
  6.  * This code is freely redistributable upon the conditions that this 
  7.  * notice remains intact and that modified versions of this file not
  8.  * be included as part of the PDC Software Distribution without the
  9.  * express consent of the copyright holders.  No warrantee of any
  10.  * kind is provided with this code.  For further information, contact:
  11.  *
  12.  *  PDC Software Distribution    Internet:                     BIX:
  13.  *  P.O. Box 4006             or hummel@cs.uiuc.edu            lhummel
  14.  *  Urbana, IL  61801-8801       petersen@uicsrd.csrd.uiuc.edu
  15.  */
  16.  
  17. /* fseek - seeks relative some part of an I/O stream */
  18.  
  19. #include <stdio.h>
  20.  
  21. extern int _doflush();
  22. extern long    lseek();
  23.  
  24. fseek( fp, position, mode )
  25. FILE *fp;
  26. long position;
  27. int  mode;
  28. {
  29.     int i;
  30.     long lseek();
  31.  
  32.     fp->_fileflag &= ~_FILEATEOF;
  33.     if ( fp->_fileflag & _FILEISDIRTY ) {
  34.         if (_doflush(fp, -1))
  35.             return EOF;
  36.     }
  37.     else if (mode == 1 && fp->_filecpos)
  38.         position -= (long)(fp->_fileend - fp->_filecpos);
  39.     fp->_filecpos = NULL;
  40.     fp->_fileend = NULL;
  41.  
  42.     if ( lseek((int)fp->_fileunit, position, mode) < 0)
  43.         return EOF;
  44.     return 0;
  45. }
  46.  
  47.    long
  48. ftell(fp)
  49. FILE *fp;
  50. {
  51.     long position;
  52.  
  53.     position = lseek((int)fp->_fileunit, 0L, 1);
  54.  
  55.     if ( fp->_fileflag & _FILEISDIRTY)
  56.         position += (long)(fp->_filecpos - fp->_filebufp);
  57.     else if ( fp->_filecpos )
  58.         position -= (long)(fp->_fileend - fp->_filecpos);
  59.  
  60.     return position;
  61. }
  62.